﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Windows.Media.Imaging;

namespace BarleyBreak
{
    public class Cell
    {
        // current positions     
        public int X
        {
            get;
            set;
        }

        public int Y
        {
            get;
            set;
        }

        public int Position
        {
            get;
            set;
        }       

        // real positions
        private int m_xReal;
        private int m_yReal;

        private Image m_image = new Image();
        private String m_imagePath;

        private bool m_emptyCell = false;

        public void SetEmptyCell()
        {
            m_emptyCell = true;
        }

        public bool IsCellEmpty()
        {
            return m_emptyCell;
        }

       

        public void Init(int position, String picturePath)
        {  
            m_xReal = position % 3;
            m_yReal = position / 3;
            Position = position;

            m_imagePath = picturePath;

            Uri uri = new Uri(m_imagePath, UriKind.Relative);
            m_image.Source = new BitmapImage(uri);
      
            m_image.ImageFailed += (s, args) =>
            {
                MessageBox.Show(args.ErrorException.Message);
            };
        }

        public bool Correct()
        {
            if (m_xReal == X && m_yReal == Y)
            {
                return true;
            }

            return false;
        }
        
        public void SetCoordinates(int position)
        {
            X = position % 3;
            Y = position / 3;
        }
        
        public void SetCoordinates(int x, int y)
        {
            X = x;
            Y = y;
        }

       
        public Image GetImage()
        {
            return m_image;
        }
    }
}
